#用while输出九九乘法表
print('='*20,'用while输出九九乘法表','='*20)
print('')
#正三角

i = 1
while i<=9:
    j = 1
    while j<=i :
        print('{}*{}={:>2}'.format(j,i,j*i),end=' ')
        j+=1
    i += 1
    print("  ")
print('='*65)


# 倒三角
i = 9
while 0< i <=9:
    j = 1
    while j <=i:
        print('{}*{}={:>2}'.format(j, i, j * i), end=' ')
        j += 1
    i -= 1
    print(' ')
print('='*65)

#右下正三角

i = 1
while i < 10:
    # j 代表被乘数
    j = i
    while j >= 1:
        string_result = "{}*{}={:<4}".format(j, i, i * j)

        if i == j:
            print(string_result.rjust(8 * (10 - i)), end="")
        else:
            print(string_result, end="")
        j -= 1

    i += 1
    print("")
print('='*65)
i = 9
while i >= 1:
    # j 代表被乘数
    j = i
    while j >= 1:
        string_result = "{}*{}={:<4}".format(j, i, i * j)

        if i == j:
            print(string_result.rjust(8 * (10 - i)), end="")
        else:
            print(string_result, end="")
        j -= 1

    i -= 1
    print("")


# 用for循环输出九九乘法表

print("=" * 20, "for 循环实现样式", "=" * 20)
print('')

# 左下三角
for j in range(1, 10):
    '''输出一个正三角九九乘法表
       左下三角
    '''
    for i in range(1, j + 1):
        print("{}*{}={:<2}".format(i, j, i * j), end=' ')
    print('')
print('=' * 65)

# 左上三角
for j in range(9, 0, -1):

    '''输出一个倒三角九九乘法表
       左上三角
    '''
    for i in range(1, j + 1):
        print('{}*{}={:<2}'.format(i, j, i * j), end=' ')
    print(' ')
print('=' * 65)

# 右下三角
for i in range(1, 10):
    for k in range(1, 10 - i):
        print(end="       ")
    for j in range(i, 0, -1):
        print('{}*{}={:>2}'.format(j, i, j * i), end=' ')
    print("")
print('=' * 65)

# 右上三角

for i in range(9, 0, -1):
    for k in range(1, 10 - i):
        print(end="       ")
    for j in range(i, 0, -1):
        print('{}*{}={:>2}'.format(j, i, j * i), end=' ')
    print(' ')

print('=' * 65)












